<template>
	<view class="container">
		<view class="items" v-if="user!=''">
			<view class="item" @click="navigateTo('/pages/center/set-wechat')">
				<image src="https://farm-city.oss-cn-hangzhou.aliyuncs.com/static/order/zf-weixin.png" mode="widthFix"
					class="left-img"></image>
				<view class="title">微信号</view>
				<view class="right-tit">{{user.wechat_account? user.wechat_account:'未绑定'}}</view>
				<image src="https://farm-city.oss-cn-hangzhou.aliyuncs.com/static/common/more-grey.png" mode="widthFix"
					class="more-img" v-if="user.is_bind_wx==0"></image>
			</view>
			<view class="item" @click="navigateTo('/pages/center/set-zfb')">
				<image src="https://farm-city.oss-cn-hangzhou.aliyuncs.com/static/order/zf-zfb.png" mode="widthFix"
					class="left-img"></image>
				<view class="title">支付宝号</view>
				<view class="right-tit">{{user.zhifubao? user.zhifubao:'未绑定'}}</view>
				<image src="https://farm-city.oss-cn-hangzhou.aliyuncs.com/static/common/more-grey.png" mode="widthFix"
					class="more-img"></image>
			</view>
		</view>
	</view>
</template>

<script>
	var _this;
	export default {
		data() {
			return {
				user: ''
			};
		},
		methods: {
			//获取用户信息
			async get_user_info() {
				const data = await _this.$post('api/UserInfo')
				if (data.code == 200) {
					this.user = data.data.user
				} else {
					this.$u.toast(data.msg)
				}
			},
			weixin_login() {
				if (_this.user.is_bind_wx == 1) {
					return
				}
				// #ifndef H5
				uni.login({
					provider: 'weixin',
					success: function(loginRes) {
						// 登录成功
						uni.getUserInfo({
							provider: 'weixin',
							success: function(info) {
								// 获取用户信息成功, info.authResult保存用户信息
								_this.bind_weixin(info.userInfo)
							}
						})
					},
					fail: function(err) {
						// 登录授权失败  
						// err.code是错误码
						console.log(err);
					}
				});
				// #endif
			},
			async bind_weixin(userInfo) {
				const data = await _this.$post('api/bind_zfb_wx', userInfo)
				if (data.code == 200) {
					uni.$u.toast(data.msg)
					_this.get_user_info()
				} else {
					uni.$u.toast(data.msg)
				}
			}
		},
		onLoad(e) {
			_this = this;
		},
		onShow() {
			_this.get_user_info()
		},
		components: {}
	}
</script>

<style lang="scss" scoped>
	.container {
		.items {
			.item {
				background: #fff;
				border-radius: 20rpx;
				@include flex-box(row, null, center);
				height: 120rpx;
				padding: 0 30rpx;

				&:not(:last-child) {
					margin-bottom: 20rpx;
				}

				.left-img {
					width: 44rpx;
					margin-right: 20rpx;
				}

				.title {
					flex: 1;
					font-weight: 500;
					font-size: 28rpx;
				}

				.right-tit {
					color: $color-919191;
				}

				.more-img {
					margin-left: 20rpx;
					width: 24rpx;
				}
			}
		}
	}
</style>